package com.chen.palmar.project.set;

import android.os.Bundle;
import android.widget.TextView;

import com.chen.palmar.R;
import com.chen.palmar.base.BaseActivity;
import com.chen.palmar.common.datasource.DataCenter;
import com.chen.palmar.common.override.HttpSubscriber;
import com.chen.palmar.common.widget.view.AutoToolbar;
import com.primb.androidlibs.net.entity.HttpResultEntity;

import butterknife.Bind;
import rx.Subscription;

/**
 * @author Chen
 * @date 2018/1/9
 * 功能描述：
 */

public class ServiceActivity extends BaseActivity {
    @Bind(R.id.title_bar)
    TextView titleBar;
    @Bind(R.id.tool_bar)
    AutoToolbar toolBar;
    @Bind(R.id.tv_vip_name)
    TextView tvVipName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }

    @Override
    public void init() {
        toolBar.setNavigationOnClickListener(v -> ServiceActivity.this.finish());
        titleBar.setText("服务协议");

        try {
            getDataForWeb();
        } catch (Exception e) {
            e.printStackTrace();
            showToast("服务器数据格式异常");
        }
    }

    private void getDataForWeb() {
        Subscription subscribe = DataCenter.serviceInfo().subscribe(new HttpSubscriber<HttpResultEntity>(this, showLoading("加载中")) {
            @Override
            public void onNext(HttpResultEntity entity) {
                tvVipName.setText(entity.getData());
            }
        });
        subscription.add(subscribe);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_set_service;
    }

}
